<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>management</title>
<meta name="Keywords" content="" /> 
<meta name="Description" content="" />
<link type="text/css" rel="stylesheet" href="/css/management.css" />
<script src="/js/jquery-1.8.3.min.js"></script>
<script src="/plugins/My97DatePicker/WdatePicker.js"></script>
<script charset="utf-8" src="/plugins/kindeditor/kindeditor.js"></script>
<script type="text/javascript">
	var eventKDE = {
		
		editor : null,
				
		description : 'description something here...',
				
		init : function(){
			KindEditor.ready(function(K) {
				eventKDE.editor = K.create('textarea[name="description"]', {
				   allowFileManager : true,
				   items : [
						 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
						'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
						'anchor', 'link', 'unlink', '|', 'about'
					],
					afterFocus : function(){eventKDE.afterFocus()},
					afterBlur : function(){eventKDE.afterBlur()}
				}); 
				if(eventKDE.editor.text() == ''){
					eventKDE.editor.text(eventKDE.description);
				}
			});
		},
		
		afterFocus : function(){
			if(eventKDE.editor.text() == eventKDE.description){
				eventKDE.editor.html('');
			}
		},
				
		afterBlur : function(){
			if(eventKDE.editor.text() == ''){
				eventKDE.editor.text(eventKDE.description);
			}
		}
	};
    
	eventKDE.init();
</script>
</head>
<body>
<div class="wrapper">
	<div class="mod_box">
		<div class="hd"><span class="tl"></span><span class="tr"></span></div>
		<div class="bd">
			<!--面包屑 begin-->
			<div class="crumb">location：<a href="javascript:void(0);">event</a> &gt; new event</div>
			<!--面包屑 end-->
			<!--表单 begin-->
			<form action="/index.php?r=event/save" method="post" id="mainform" enctype="multipart/form-data">
				<input type="hidden" name="eid" value="{{$pageArray.row.id}}"/>
			<table class="mod_table">
				<tbody>
					<tr>
						<th><i class="must">*</i>Title：</th>
						<td>
							<input type="text" class="ipt_text" name="title" value="{{$pageArray.row.title}}"/>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Address：</th>
						<td>
							<select name="address">
								{{html_options options=$pageArray.address selected=$pageArray.row.address}}
							</select>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Vip：</th>
						<td>
							<div class="edit_show_panel">
							    <input class="ipt_radio" type="radio" value="0" name="type" {{if $pageArray.row.type eq '1'}}{{else}}checked{{/if}}/>no
							    &nbsp;&nbsp;
							    <input class="ipt_radio" type="radio" value="1" name="type" {{if $pageArray.row.type eq '1'}}checked{{/if}}/>yes
							</div>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Need Encorecard：</th>
						<td>
							<div class="edit_show_panel">
							    <input class="ipt_radio" type="radio" value="0" name="n_encorecard" {{if $pageArray.row.n_encorecard eq '1'}}{{else}}checked{{/if}}/>no
							    &nbsp;&nbsp;
							    <input class="ipt_radio" type="radio" value="1" name="n_encorecard" {{if $pageArray.row.n_encorecard eq '1'}}checked{{/if}}/>yes
							</div>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Need Creditcard：</th>
						<td>
							<div class="edit_show_panel">
							    <input class="ipt_radio" type="radio" value="0" name="n_creditcard" {{if $pageArray.row.n_creditcard eq '1'}}{{else}}checked{{/if}}/>no
							    &nbsp;&nbsp;
							    <input class="ipt_radio" type="radio" value="1" name="n_creditcard" {{if $pageArray.row.n_creditcard eq '1'}}checked{{/if}}/>yes
							</div>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Minors Permit：</th>
						<td>
							<div class="edit_show_panel">
							    <input class="ipt_radio" type="radio" value="0" name="minors" {{if $pageArray.row.minors eq '1'}}{{else}}checked{{/if}}/>no
							    &nbsp;&nbsp;
							    <input class="ipt_radio" type="radio" value="1" name="minors" {{if $pageArray.row.minors eq '1'}}checked{{/if}}/>yes
							</div>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Min：</th>
						<td>
							<input type="text" class="ipt_text ipt_text_s" name="min" value="{{$pageArray.row.min}}"/>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Limit time：</th>
						<td>
							<input type="text" class="ipt_text ipt_text_s" name="limit_time" value="{{$pageArray.row.limit_time}}"/>hours
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Period：</th>
						<td>
							<input class="ipt_date" type="text" onClick="WdatePicker()" name="start_date" value="{{$pageArray.row.start_date}}"/>
							H:<select name="start_H" class="select">
								{{html_options options=$pageArray.H selected=$pageArray.row.start_H}}
							</select>
							～  
							<input class="ipt_date" type="text" onClick="WdatePicker()" name="end_date" value="{{$pageArray.row.end_date}}"/>
							H:<select name="end_H" class="select">
								{{html_options options=$pageArray.H selected=$pageArray.row.end_H}}
							</select>
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Description：</th>
						<td><textarea name="description" style="width:800px;height:400px;visibility:hidden;">{{$pageArray.row.description}}</textarea></td>
					</tr>
					<tr>
						<th><i class="must">*</i>Upload Layout Image：</th>
						<td>
							<input type="file" name="layout"/>
							{{if $pageArray.row.layout}}
							<br/>
							<img src="{{$pageArray.row.layout}}"/>
							{{/if}}
						</td>
					</tr>
					<tr>
						<th><i class="must">*</i>Tables：</th>
						<td>
							<div class="edit_modi_pannel">
								<ul class="edit_pannel">
									{{if $pageArray.row.tables}}
									{{foreach from=$pageArray.row.tables key=key item=item name=tables}}
									<li class="pannel_item">
										<input type="checkbox" name="ordered[]" value="{{$item.id}}"/>
										<b>num:</b><input class="ipt_text ipt_text_s" type="text" name="num[{{$smarty.foreach.tables.index}}]" value="{{$item.num}}"/> 
										<b>max:</b><input class="ipt_text ipt_text_s" type="text" name="max[{{$smarty.foreach.tables.index}}]" value="{{$item.max}}"/>
										<b>ordered:</b>{{if $item.ordered == '1'}}yes{{else}}no{{/if}}
										<!--<i class="i_add" onclick="tabAdd(this);"></i><i class="i_del" onclick="tabDel(this);"></i>-->
									</li>
									{{/foreach}}
									<br/>
									<input type="button" value="Reservation" name="reservation"/>
									<input type="button" value="Release Reservation" name="release"/>
									{{else}}
									{{foreach from=$pageArray.defaultTable key=key item=item name=tables}}
									<li class="pannel_item">
										<b>num:</b><input class="ipt_text ipt_text_s" type="text" name="num[{{$smarty.foreach.tables.index}}]" value="{{$item.num}}"/> 
										<b>max:</b><input class="ipt_text ipt_text_s" type="text" name="max[{{$smarty.foreach.tables.index}}]" value="{{$item.max}}"/>
										<b>ordered:</b><input type="radio" name="ordered[{{$smarty.foreach.tables.index}}]" value='0' checked>no &nbsp: <input type="radio" name="ordered[{{$smarty.foreach.tables.index}}]" value='1'>yes
										<!--<i class="i_add" onclick="tabAdd(this);"></i><i class="i_del" onclick="tabDel(this);"></i>-->
									</li>
									{{/foreach}}
									{{/if}}
								</ul>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
			<!--表单 end-->
			<!--表格外提交区域 begin-->
			<div class="btn_tool">
				<a class="btn" href="javascript:void(0);" onclick="formSubmit();"><span>commit</span></a>
				<a class="btn_2" href="javascript:void(0);" onclick="turnBack();"><span>return</span></a>
			</div>
			<!--表格外提交区域 end-->
		</div>
		<div class="ft"><span class="bl"></span><span class="br"></span></div>
	</div>
</div>
<script type="text/javascript">
	var index;
	function tabAdd(obj){
		var temp_obj = $(obj).parent().clone();
		var temp_index = index;
		$(temp_obj).find("input[type='text']").eq(0).attr({"name":"num[" + temp_index + "]"});
		$(temp_obj).find("input[type='text']").eq(1).attr({"name":"max[" + temp_index + "]"});
		$(temp_obj).insertAfter($(obj).parent());
		index++;
	}
	function tabDel(obj){
		$(obj).parent().remove();
	}
	function formSubmit(){
		var commit = true;
		var tables = 0;
		
		if($("input[name='title']").val() == ''){
			alert('title not null');
			return;
		}
		if($("input[name='min']").val() != '' && isNaN($("input[name='min']").val()) == true ){
			alert('min must be numeric ');
			return;
		}
		var limit_time_reg = /^[0-9]+$/;
		if(!limit_time_reg.test($("input[name='limit_time']").val())){
			alert('limit_time must be numeric ');
			return;
		}
		if($("input[name='start_date']").val() == '' || $("input[name='end_date']").val() == ''){
			alert('period not null');
			return;
		}
		if(eventKDE.editor.text() == '' || eventKDE.editor.text() == eventKDE.description){
			alert('description not null');
			return;
		}
		if($("input[type='file']").val() == '' && $("input[name='eid']").val() == ''){
			alert('layout not null');
			return;
		}
		
		$(".pannel_item").each(function(){
			if($(this).find("input").eq(0).val() != "" || $(this).find("input").eq(1).val() != ""){
				tables++;
				if($(this).find("input").eq(0).val() == '' || $(this).find("input").eq(1).val() == ''){
					alert("必填");
					commit = false;
					return false;
				}
				if(!$.isNumeric($(this).find("input").eq(0).val()) || !$.isNumeric($(this).find("input").eq(1).val())){
					alert("数字");
					commit = false;
					return false;
				}
			}
		});
		if(tables == 0){
			alert("tables not null");
			return false;
		}
		if(commit){
			$("textarea[name='description']").val(eventKDE.editor.text());
			$("#mainform").submit();
		}
	}
	$(document).ready(function(){
		index = $(".pannel_item").length;
		
		$("input[name='reservation']").click(function(){
			if($(".pannel_item").find("input[type='checkbox']:checked").length > 0){
				var tids = "";
				$(".pannel_item").find("input[type='checkbox']:checked").each(function(){
					tids += $(this).val() + ',';
				});
				$.ajax({
					type : "get",
					url : "/index.php?r=event/reserve&tids="+tids,
					success : function(msg){
						if(msg == "success"){
							alert("success!");
							window.location.reload();
						}else{
							alert("fail");
							return false;
						}
					}
				});
			}else{
				alert("chose first");
				return false;
			}
		});
		
		$("input[name='release']").click(function(){
			if($(".pannel_item").find("input[type='checkbox']:checked").length > 0){
				var tids = "";
				$(".pannel_item").find("input[type='checkbox']:checked").each(function(){
					tids += $(this).val() + ',';
				});
				$.ajax({
					type : "get",
					url : "/index.php?r=event/release&tids="+tids,
					success : function(msg){
						if(msg == "success"){
							alert("success!");
							window.location.reload();
						}else{
							alert("fail");
							return false;
						}
					}
				});
			}else{
				alert("chose first");
				return false;
			}
		});
	});
</script>
</body>
</html>